<!-- 公告 -->
<template>
    <div class="announce" :style="boxStyle">
        <div class="announce-mode" :style="{
            textAlign: element.eles.style['text-align']
        }">
            <template v-if="['announce1', 'announce2', 'announce3', 'announce4'].includes(selectImg)">
                <span
                    :style="{
                        fontSize: element.eles.style['font-size'],
                        color: element.eles.customFeature.lineBackgroundColor,
                        height: `${element.eles.customFeature.height}px`,
                        lineHeight: `${element.eles.customFeature.height}px`
                    }"
                    class="announce-icon"
                >
                    <el-icon>
                        <icon-announce1 v-if="selectImg === 'announce1'" />
                        <icon-announce2 v-if="selectImg === 'announce2'" />
                        <icon-announce3 v-if="selectImg === 'announce3'" />
                        <icon-announce4 v-if="selectImg === 'announce4'" />
                    </el-icon>
                </span>
            </template>
            <template v-else>
                <span class="announce-icon">
                    <img :src="selectImg" />
                </span>
            </template>

            <template v-if="element.eles.customFeature.mode === 0">
                <div class="scroll-box" :style="{
                    maxWidth: `${element.eles.customFeature.width}px`
                }">
                    <div class="scroll-content0" :style="{
                        animation: `scroll ${element.eles.customFeature.interval * element.eles.content.length}s linear 0s infinite normal none running`
                    }">
                        <template v-for="(item, index) in element.eles.content" :key="index">
                            <div class="announce-content" :style="{
                                color: element.eles.style.color,
                                fontSize: element.eles.style['font-size'],
                                fontWeight: element.eles.style['font-weight'],
                                fontStyle: element.eles.style['font-style'],
                                textDecoration: element.eles.style['text-decoration'],
                                maxWidth: `${element.eles.customFeature.width}px`,
                                lineHeight: `${element.eles.customFeature.height}px`
                            }">
                                {{ item.secContent }}
                            </div>
                        </template>
                    </div>
                </div>
            </template>
            <template v-else>
                <div class="announce-mode1-box" :style="{
                    height: `${element.eles.customFeature.height}px`
                }">
                    <div class="announce-mode1" :style="{
                        animation: `scroll2 ${element.eles.customFeature.interval * element.eles.content.length}s linear 0s infinite normal none running`
                    }">
                        <template v-for="(item, index) in element.eles.content" :key="index">
                            <div class="scroll-content1" :style="{
                                top: '0px',
                                maxWidth: '285px',
                                color: element.eles.style.color,
                                fontSize: element.eles.style['font-size'],
                                lineHeight: `${element.eles.customFeature['height']}px`
                            }">
                                {{ item.secContent }}
                            </div>
                        </template>
                    </div>
                </div>
            </template>
        </div>
    </div>
</template>

<script>
import { defineComponent, toRefs, computed } from 'vue'
export default defineComponent({
    name: 'WidgetAnnounce',
    props: {
        element: {
            type: Object,
            default: () => ({})
        }
    },
    setup(props, { emit }) {
        const { element } = toRefs(props)

        const selectImg = computed(() => element.value.eles.customFeature.selectImg)

        const boxStyle = computed(() => {
            const style = element.value.eles.style || {}
            const customFeature = element.value.eles.customFeature || {}
            return {
                marginTop: style['margin-top'],
                marginLeft: style['margin-left'],
                marginRight: style['margin-right'],
                backgroundColor: style['background-color'],
                backgroundImage: style['background-image'],
                borderStyle: style['border-style'],
                borderColor: style['border-color'],
                borderWidth: style['border-width'],
                boxShadow: style['box-shadow'],
                height: `${customFeature['height']}px`
            }
        })
        
        return {
            element,
            selectImg,
            boxStyle
        }
    }
})
</script>

<style lang="less" scoped>
@import './widget-announce.less';
</style>

<style>
@keyframes scroll {
    0% {
        left: 0;
    }

    100% {
        left: -100%;
    }
}

@keyframes scroll2 {
    0% {
        top: 0;
    }

    100% {
        top: -100%;
    }
}
</style>